//
//  JosinFamilyVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/28.
//  Copyright © 2020 tym. All rights reserved.
//

#import "JosinFamilyVC.h"
#import "UIButton+Gradient.h"
#import "Colors.h"
#import "UIImageView+YPImage.h"
#import "WHToast.h"
#import "FamilyService.h"
#import "UIView+ZFFrame.h"
#import "Sizes.h"

@interface JosinFamilyVC ()

@property(nonatomic,weak) IBOutlet UIImageView *headImage;
@property(nonatomic,weak) IBOutlet UILabel *nameLab;
@property(nonatomic,weak) IBOutlet UILabel *descLab;

@property(nonatomic,weak) IBOutlet UIButton *joinBtn;

@property(nonatomic,strong) FamilyService *service;
@end

@implementation JosinFamilyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    [self addTitle:@"加入已有家庭"];
    
    [self initUI];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.nameLab.text = _familyModel.familyName;
    self.descLab.text = _familyModel.familyDesc;
    
    [self.headImage yp_setImageUlr:[_familyModel getFamileHeadImage] placeHolder:@"icon_home3"];
    
}
-(void)setFamilyModel:(FamilyModel *)familyModel{
    _familyModel = familyModel;
    
}

-(void)initUI{
    
    self.joinBtn.layer.cornerRadius = 5;
    self.joinBtn.layer.masksToBounds = YES;
    self.joinBtn.zf_width = ScreenWidth - 60;
    [self.joinBtn gradientButtonWithSize:CGSizeMake(300, 44) colorArray:@[(id)rgba(139, 175, 255),(id)rgba(76, 132, 255)] percentageArray:@[@(0.5),@(1)] gradientType:GradientFromLeftTopToRightBottom];
    self.headImage.layer.cornerRadius = self.headImage.zf_width/2;
    self.headImage.layer.masksToBounds = YES;
}

-(FamilyService*)service{
    if (_service == nil) {
        _service = [[FamilyService alloc] init];
    }
    return _service;
}

-(IBAction)joinFamilyAction:(id)sender{
    TYMWeak(self);
    [self.service getFamilyuserapplyFamilyId:self.familyModel.familyId completion:^(LMJBaseResponse * responObjec) {
        if(!responObjec.message){
            [WHToast showMessage:@"申请成功" duration:2 finishHandler:^{
                [weakself.navigationController popViewControllerAnimated:YES];
            }];
        }else{
            [WHToast showMessage:responObjec.message duration:2 finishHandler:nil];
        }
    }];
}

@end
